void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(PA1, PWM);
  pinMode(PA0, PWM);
  pwmWrite(PA1, 0);
  pwmWrite(PA0, 0);
}
char buffer [20];
int brightness = 0;

void loop() {
  // put your main code here, to run repeatedly:
  if (Serial.available() > 0) {

    int responsedatalength = Serial.readBytes(buffer, 20);
    if (responsedatalength = 4) {
      //responsedata= Serial.parseInt();

      //        brightness=makeword(buffer[0],buffer[1]);
      //brightness = buffer[1] << 8 | buffer[0];  // 第一位为高位
      brightness = buffer[0] + (buffer[1] << 8) + (buffer[2] << 16) + (buffer[3] << 24);
      Serial.write(brightness);
      if (brightness >= 0) {
        pwmWrite(PA0, brightness);
        pwmWrite(PA1, 0);
      }
      
      if (brightness < 0) {
        pwmWrite(PA1, brightness);
        pwmWrite(PA0, 0);
      }
    }
  }
}
